<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include_once(APPPATH."libraries/AdminController.php");
class Report_pagaris extends AdminController {  
	var $bulan = array();
	var $bav_type = "";
	var $bav_title = "";
	function __construct()   
	{
		parent::__construct();    
		$this->_set_action();
		$this->bav_type = 'garis';
		$this->bav_title = 'Garis';
		$this->_set_action(array("detail","delete"),"ITEM");
		$this->_set_title('Transaksi > Report  PA '.$this->bav_title.'  PT BAV');
		$this->DATA->table="tm_bav";
		$this->cat_search = $this->get_cabang();
		$this->folder_view = "transaksi/";
		$this->_set_cat_search(array("all"	=> $this->cat_search));	
		$this->load->model("mdl_report_bav","A");
		$this->prefix_view = 'report_bav';
		
		$this->output->enable_profiler(FALSE);
	}
	
	function get_cabang(){
		$opt = array();
		
		$this->DATA->table = "tm_pialang_cabang";
		
		$s = $this->DATA->_getall();
		
		foreach($s as $r){
			$opt[$r->cabang_id] = $r->cabang_name;
		}
		return $opt;
	}
	
	function get_excel($col="", $ds="", $de = ""){
		if(trim($col) != ""){
			$param = array(
						"column"	=> $col,	
						"type"		=> $this->bav_type,				
						"keyword"	=> 'all'
					) ;
			
			if(trim($ds) != "all" && trim($de) != "all"){
				$param["start_date"] = $ds;
				$param["end_date"] = $de;
			}
			
			$data['client']	= array();
			$data['ex']= $this->A->data_detail( $param );
			
			if( count($data['ex']['data']) ){
				$cl = $data['ex']['data'][0]->bav_cabang;
				$tbl = "";
				$sql = $this->db->query("
					SELECT * FROM tm_pialang_cabang WHERE cabang_id = '".dbClean($cl)."'
				")->row();
				if(count($sql) > 0)
					$data['client'] = $sql;
			}
			
			$this->_v($this->folder_view.$this->prefix_view."_excel",$data, FALSE);
		}
	}
	function index(){
		
		$this->jCfg['isearch']['status'] 		= "all";
		$this->jCfg['isearch']['start_date'] 	= "";
		$this->jCfg['isearch']['end_date'] 		= "";
		$this->jCfg['isearch']['per_page'] 		= "10000";
		$this->_releaseSession();
		
		$this->_set_desc_title('Daftar Upload Excel Kecelakaan Diri');	
		
		$this->data_table = $this->A->data_detail(array(
			"type"		=> $this->bav_type
		));
		
		$data = $this->_data(
			array(
				'base_url'		=>$this->own_link.'search/'
			)
		);	
		
		$this->_v($this->folder_view.$this->prefix_view,$data);
	}
	
	function search(){
		$this->_set_desc_title('Daftar Upload Excel Kecelakaan Diri');	
		$this->load->helper('url');		
		$this->uri_segment = 5;
		$this->per_page = 1000;
		
		//debugCode($_POST);
		$column = '';				
		if( isset($_POST['column']) && isset($_POST['keyword']) ){
			$column = $_POST['column'];
			$this->setiSearch(array(
				"start_date"=> dbClean($_POST['dstart']),
				"end_date"	=> dbClean($_POST['dend'])
			));
		}else{
			$column =  $this->uri->segment(4);
		}	
		
		$this->data_table = $this->A->data_detail( array(
								"column"	=> $column,
								"type"		=> $this->bav_type,
								"start_date"=> $this->jCfg['isearch']['start_date'],
								"end_date"	=> $this->jCfg['isearch']['end_date'],
								"keyword"	=> 'all'
							) );
		
		$data = $this->_data(
			array(
				'base_url'		=>$this->own_link.'search/'.$column
			)
		);	
		
		
		$this->header_page['col']=$column;	
		$this->header_page['cat_search'] = array($column	=>	$this->cat_search);	
		$this->_v($this->folder_view.$this->prefix_view,$data);
	}

}
